
from src.db import dbm, dbs
from sqlalchemy.orm import scoped_session
from src.core.variables.status import SUCCESS_CODE_CUSTOMIZE


def all_count():
    with dbm.get("hosting_Java") as db_session:
        db_session: scoped_session
        java_all = db_session.query(dbs.hosting_Java.App).count()
        java_live = db_session.query(dbs.hosting_Static.App).filter(dbs.hosting_Static.App.status == 'running').count()
        java_deploy = db_session.query(dbs.hosting_Static.App_backup).count() + java_all
    with dbm.get("hosting_Static") as db_session:
        db_session: scoped_session
        static_all = db_session.query(dbs.hosting_Static.App).count()
        static_live = db_session.query(dbs.hosting_Static.App).filter(dbs.hosting_Static.App.status == 'mapping').count()
        static_deploy = db_session.query(dbs.hosting_Static.App_backup).count() + static_all
        
    result = {
        'all': java_all + static_all,
        'live': java_live + static_live,
        'deploy': java_deploy + static_deploy
    }
    return result